package org.anderground.editor.gui.properties.station;

import org.anderground.core.model.Station;
import org.anderground.core.util.Coord;
import org.anderground.editor.edits.EditsManager;
import org.anderground.editor.edits.SetStationLocationAction;

public class StationLocationProperty extends AbstractStringStationProperty {

	@Override
	protected String getValue(Station station) {
		String text = "(0,0)";
		if (station.getLocation() != null) {
			text = "";
			text += "(" + station.getLocation().getX() / 1000000d + ";"
					+ station.getLocation().getY() / 1000000d + ")";
		}
		return text;
	}

	@Override
	protected void setValue(Station station, String cellEditorValue) {
		Coord newCoord = Coord.parseLocation(cellEditorValue);
		EditsManager.getInstance().performAction(
				new SetStationLocationAction(newCoord, station));
	}

	@Override
	public String getPropertyName() {
		return "Location";
	}

	@Override
	public boolean isEditable() {
		return true;
	}
}
